package com.example.teachingSystem.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Data
public class UserInfoVo implements Serializable {
    private Long id;
    private String name;
    private String username;
    private String email;
    private String avatar;
    private String sign;
    private Integer sex;
    private List<OptionVo> roles;
    private List<Long> roleIds;
    private Integer status;
    private Integer deleted;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date updateTime;
    public void setRoles(String roles) {
        List<OptionVo> optionVos = new ArrayList<>();
        List<String> roldIdAndNames = Arrays.asList(roles.split(","));
        roldIdAndNames.forEach(item->{
            List<String> oneRole = Arrays.asList(item.split(":"));
            OptionVo optionVo = new OptionVo();
            optionVo.setId(Long.valueOf(oneRole.get(0)));
            optionVo.setName(oneRole.get(1));
            optionVos.add(optionVo);
        });
        this.roles = optionVos;
    }

    public void setRoleIds(String roleIds) {
        List<Long> ids = new ArrayList<>();
        Arrays.asList(roleIds.split(",")).forEach(item->{
            ids.add(Long.valueOf(item));
        });
        this.roleIds =  ids;
    }
}
